package com.mashibing.service.impl;

import com.mashibing.internalcommon.dto.PassengerUser;
import com.mashibing.internalcommon.dto.ResponseResult;
import com.mashibing.internalcommon.dto.TokenResult;
import com.mashibing.internalcommon.remote.ServicePassengerUserClient;
import com.mashibing.internalcommon.util.JwtUtils;
import com.mashibing.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;
    @Override
    public ResponseResult<PassengerUser> getUser(String token) {

        // 解析token
        TokenResult tokenResult = JwtUtils.checkToken(token);

        // 调用feignClient查询用户信息
        String phone = tokenResult.getPhone();
        ResponseResult<PassengerUser> user = servicePassengerUserClient.getUser(phone);
        log.info("电话为" + phone + "的用户信息为：" + user);

        return ResponseResult.success(user.getData());
    }
}
